package hadoop.WordCount;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class reduce extends Reducer<Text, IntWritable,Text,IntWritable> {
    /*
    * 经过shufll以后数据格式
    * <java,Iterable[1,1,1]>
    * <python,Iterable[1]>
    * <hadoop,Iterable[1,1]>
    * */
    IntWritable L2 = new IntWritable();
    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Reducer<Text, IntWritable, Text, IntWritable>.Context context) throws IOException, InterruptedException {
        // key:java
        // values:Iterable[1,1,1]
        int sum = 0;
        for (IntWritable i: values) {
            sum += i.get(); // i.get() --> 1
        }
        L2.set(sum);
        context.write(key,L2);
    }
}
